﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GroupList.aspx.cs" Inherits="background.Manager.Enterprise.Forms.GroupList" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="../../Styles/index.css" rel="stylesheet" />
    <script src="../../Scripts/jquery-1.8.2.min.js"></script>
    <script src="../../Scripts/layer/layer.js"></script>

    <script type="text/javascript">

        function massDelete() {
            var d = new Array();
            $("input[name='idbox']:checked").each(function () { d.push($(this).val()); })
            if (d.length == 0) { layer.msg("请选择要删除的项"); return; }
            if (confirm("确定要删除所选项吗？")) {
                $.post("Action/Temp.ashx", { action: "deleteGroup", idList: d.join(',') }, function (ret) {
                    if (ret) {
                        layer.msg("删除成功，2秒后自动刷新页面", { icon: 1, time: 2000 }, function () { window.location.reload(); });
                    } else {
                        layer.msg("对不起删除失败，稍后再试", { icon: 2 });
                    }
                })
            }
        }
        function deletes(id) {
            if (confirm("确定要删除吗？")) {
                $.post("Action/Temp.ashx", { action: "deleteGroup", idList: id }, function (ret) {
                    if (ret) {
                        layer.msg("删除成功，2秒后自动刷新页面", { icon: 1, time: 2000 }, function () { window.location.reload(); });
                    } else {
                        layer.msg("对不起删除失败，稍后再试", { icon: 2 });
                    }
                })
            }
        }
        function checkboxAll(obj) {
            $("input[name='idbox']").attr("checked", $(obj).is(":checked"));
        }
        function update(_id) {

            $.getJSON("Action/Temp.ashx", { action: "getGroup", id: _id }, function (json) {
                var h = new Array(), _area = [], son = json[0];
                h.push('<table id="text" border="0" cellpadding="0" cellspacing="0" class="table">');
                h.push('<tr><th>表单名称</th><td>');
                h.push('<input type="text" id="name" class="text" value="' + son.Name + '" />');
                h.push('</td></tr>');
                _area = ['420px', '220px'];
                h.push('<tr><th style="vertical-align:top">表单介绍</th><td>');
                h.push('<textarea type="text" id="desc" class="text" style="height:50px;width:276px;" >' + son.Desc + '</textarea>');
                h.push('</td></tr>');
                h.push('</table>');
                layer.open({
                    type: 1,
                    title: "更新，表单内容",
                    area: _area,
                    btn: ["保存"],
                    content: h.join(''),
                    yes: function () {
                        var _name = $("#name"),
                            _desc = $("#desc");
                        if ($.trim(_name.val()).length == 0) { layer.msg("请输入名称"); _name.focus(); return; }
                        $.post("Action/Temp.ashx", { action: "changeGroup", name: _name.val(), desc: _desc.val(), id: _id }, function (ret) {
                            if (ret) {
                                layer.msg("恭喜您，更新成功", { icon: 1, time: 2000 }, function () { window.location.reload(); });
                            } else {
                                layer.msg("对不起更新失败，稍后再试", { icon: 2 });
                            }
                        });
                    }
                })
            })
        }
    </script>
</head>
<body>
    <div class="top">
        <strong>表单管理</strong>
        <span style="float: right"><a href="javascript:history.back();">
            <img src="../../Images/bak.png" />后退</a></span>
    </div>
    <div class="main">
        <div>
            <div class="tool_search">
                <input type="button" class="sbtn" value="创建表单" onclick="window.location.href = 'AddTemp.aspx'" />&nbsp;&nbsp;<input type="button" class="sbtn" value="批量删除" onclick="    massDelete()" />
            </div>
            <table border="0" cellpadding="0" cellspacing="0" class="listtable">
                <tr>
                    <th class="th" style="width: 20px">
                        <input type="checkbox" onchange="checkboxAll(this)" /></th>
                    <th class="th">编号</th>
                    <th class="th">用户提交</th>
                    <th class="th">表单名</th>
                    <th class="th">表单介绍</th>
                    <th class="th">创建日期</th>
                    <th class="th thlast">操作</th>
                </tr>
                <%System.Data.DataTable dt= Codes.Forms.getList(int.Parse(string.IsNullOrEmpty(Request["p"])?"1":Request["p"]), 10); %>
                <%foreach(System.Data.DataRow dr in dt.Rows) {%>
                <tr>
                    <td class="td">
                        <input type="checkbox" name="idbox" value="<%=dr["ID"] %>" /></td>
                    <td class="td txtcenter"><%=dr["ID"] %></td>
                    <td class="td txtcenter"><a href="#">查看</a></td>
                    <td class="td"><%=dr["Name"] %>&nbsp;<a style="text-decoration: underline" href="TitleList.aspx?groupid=<%=dr["id"] %>">管理字段(<%=dr["titleCount"] %>)</a></td>
                    <td class="td" style="line-height: 20px; width: 200px">
                        <div style="width: 200px"><%=dr["Desc"] %></div>
                    </td>
                    <td class="td"><%=Codes.h.ManuTime(((DateTime)dr["addtime"]).ToString("yyyy/MM/dd HH:mm")) %></td>
                    <td class="td tdlast txtcenter">
                        <a href="javascript:update(<%=dr["id"] %>);">
                            <img src="../../Images/edit.png" class="tool_edit" />编辑</a>
                        <a href="javascript:void(0);" onclick="deletes(<%=dr["id"] %>)">
                            <img src="../../Images/delete.png" class="tool_delete" />删除</a></td>
                </tr>
                <%} %>
            </table>
            <div class="tcdPageCode"></div>
            <script src="../../Scripts/jquery.page.js"></script>
            <script>
                $(".tcdPageCode").createPage({
                    pageCount: '<%=Math.Ceiling((double)Codes.Forms.getListCount()/10)%>',
                    current: '<%=string.IsNullOrEmpty(Request["p"])?"1":Request["p"]%>',
                    backFn: function (p) {
                        window.location.href = "?p=" + p;
                    }
                });
            </script>
        </div>
    </div>
    <!--#include file='../../Include/footer.html'-->
</body>
</html>
